<?php //if(!empty($reportItems)): foreach($reportItems as $k=>$reportItem): ?>	
	<table class="addpixelbox" id="addpixelbox">
      		<tr>
           		<td>Campaign:</td>
           		<td>
               		<select id="cam"></select>
            	</td>
         	</tr>
         	<tr>
             	<td>Publisher:</td>
             	<td>
                	<select id="pub"></select>
              	</td>
          	</tr>
          	<tr>
             	<td>Placement:</td>
              	<td>
                  	<select id="pla"></select>
               	</td>
          	</tr>
          	<tr>
             	<td>Pixel Position:</td>
               	<td>
                  	<select id="position">
	                   	<option value="">--Choose a Pixel Position--</option>
	                  	<option value="0" <?php echo ('0' == $position) ?  'selected="selected"' : ''; ?>>basic_reg</option>
	                   	<option value="1" <?php echo ('1' == $position) ?  'selected="selected"' : ''; ?>>full_reg</option>
               		</select>
               	</td>
           	</tr>
          	<tr>
             	<td>Controlled CR:</td>
               	<td><input type="text" id="peak" />%</td>
          	</tr>
       		<tr>
              	<td colspan="2" class="t-right">
       				<label id="addPixellabel" style="color:red;"></label>
              		<input type="button" value="Save" id="save" />
              	</td>
        	</tr>
 	</table>
<?php //endforeach; endif; ?>

<script type="text/javascript">
	$('#addpixelbox').dialog({
		autoOpen: false,
		height: 'auto',
		width: 'auto',
		modal: true,
		buttons: {OK: function(){
						$( this ).dialog( "close" );	
					  }
				 },
	});

	$(".addpixelbtn").click(function(){
		$('#addpixelbox').dialog('open');
		
		$("#addPixellabel").html('');	
		var cam = $("#cam"+$(this).attr("id")).html();
		var pub = $("#pub"+$(this).attr("id")).html();
		var pla = $("#pla"+$(this).attr("id")).html();

		$("#addpixelbox select:#cam").html("<option value='"+cam+"'>"+cam+"</option>");
		$("#addpixelbox select:#pub").html("<option value='"+pub+"'>"+pub+"</option>");
		$("#addpixelbox select:#pla").html("<option value='"+pla+"'>"+pla+"</option>");
		if(cam == '' || pub =='' || pla =='' || cam == null || pub ==null || pla ==null){
			$.ajax({
				type: 'GET',
				url: '<?php echo url('report/getuserpixel');?>',
				data: {
						camval: (cam == null)? '' : cam,
						pubval: (pub == null)? '' : pub,
						plaval: (pla == null)? '' : pla
					  },
				success: function(data){
							data = eval('('+data+')');
							
							if(cam == '' || cam == null){
								cam = data['cam'];
								$("#addpixelbox select:#cam").html('');
								for(var i in cam){
									$("#addpixelbox select:#cam").append("<option value='"+cam[i]['cam']+"'>"+cam[i]['cam']+"</option>");
								}
							}
							if(pub == '' || pub == null){
								pub = data['pub'];
								$("#addpixelbox select:#pub").html('');
								for(var i in pub){
									$("#addpixelbox select:#pub").append("<option value='"+pub[i]['pub']+"'>"+pub[i]['pub']+"</option>");
								}
							}
							if(pla == '' || pla == null){
								pla = data['pla'];
								$("#addpixelbox select:#pla").html('');
								for(var i in pla){
									$("#addpixelbox select:#pla").append("<option value='"+pla[i]['pla']+"'>"+pla[i]['pla']+"</option>");
								}
							}
						 }
			});
		}
		
		
	});

	$("#save").click(function(){
		var btn = $(this);
		var peak=$("#peak").val();
		if((!isNaN(peak)) && peak<=100 && peak!=""){
			$.ajax({
				type: 'POST',
				url: "<?php echo url('pixelManager/insert');?>",
				data: {
						campaign: $("#addpixelbox select:#cam").val(),
						pub: $("#addpixelbox select:#pub").val(),
						pla: $("#addpixelbox select:#pla").val(),
						position: $("#addpixelbox #position").val(),
						peak: $("#peak").val()
					  },
				success: function(data){
							$("#addPixellabel").html(data);
						 }
			});
		}else{
			$("#addPixellabel").html('Invalid Peak!');
			return false;
		}
	});
</script>